package com.changgou.web.gateway.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpCookie;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;

/**
 * @Author: 陈安
 * @Date: 2020/12/14$ 20:55$
 * @Description: $todo$
 * @Version 1.0
 */
@Service
public class AuthService {
    @Autowired
    private StringRedisTemplate redisTemplate;


    //从cookie中获取jti的值
    public String getJtiFromCookie(ServerHttpRequest request) {
        HttpCookie uid = request.getCookies().getFirst("uid");
        if (uid != null) {
            String value = uid.getValue();
            return value;
        }
        return null;
    }

    //从redis中获取jwt
    public String getJwtFromRedis(String jti) {
        String jwt = redisTemplate.boundValueOps(jti).get();
        return jwt;
    }
}
